home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 6 / develop 6 code / TCP / NewsWatcher / NewsWatcher 2.0d15 source / source / init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-25  |  4.0 KB  |  177 lines  |  [TEXT/KAHL]

  1. /*----------------------------------------------------------------------------
  2.  
  3.     init.c
  4.  
  5.     This module handles initialization of the program.
  6.     
  7.     Portions copyright © 1990, Apple Computer.
  8.     Portions copyright © 1993, Northwestern University.
  9.  
  10. ----------------------------------------------------------------------------*/
  11.  
  12. #include <GestaltEqu.h>
  13. #include <stdio.h>
  14. #include <string.h>
  15.  
  16. #include "glob.h"
  17. #include "init.h"
  18. #include "menus.h"
  19. #include "util.h"
  20. #include "dlgutil.h"
  21. #include "aevt.h"
  22. #include "prefs.h"
  23. #include "nntp.h"
  24. #include "full.h"
  25. #include "newsrc.h"
  26. #include "killfile.h"
  27. #include "log.h"
  28.  
  29.  
  30.  
  31. /*----------------------------------------------------------------------------
  32.     SetUpMenus 
  33.     
  34.     Draws the pull-down menus onto the screen.     
  35. ----------------------------------------------------------------------------*/
  36.  
  37. static void SetUpMenus (void)
  38. {
  39.     Handle mbar;
  40.     
  41.     mbar = GetNewMBar(kMBarID);
  42.     SetMenuBar(mbar);
  43.     AddResMenu(GetMHandle(kAppleMenu), 'DRVR');
  44.     
  45.     #ifndef FILTERS
  46.     {
  47.         short item;
  48.         MenuHandle theMenu;
  49.         Str255 theCommand;
  50.         
  51.         theMenu = GetMHandle(kSearchMenu);
  52.         for (item = kGroupKillItem; item <= kKillSubjectItem; item++) {
  53.             GetItem(theMenu, item, theCommand);
  54.             BlockMove(theCommand+1, theCommand+2, *theCommand+1);
  55.             theCommand[1] = '¬';
  56.             (*theCommand)++;
  57.             SetItem(theMenu, item, theCommand);
  58.         }
  59.     }
  60.     #endif
  61.     
  62.     DrawMenuBar();
  63. }
  64.  
  65.  
  66.  
  67. /*----------------------------------------------------------------------------
  68.     Init 
  69.         
  70.     Initializes the program.     
  71. ----------------------------------------------------------------------------*/
  72.  
  73. void Init (void)
  74. {
  75.     EventRecord ev;
  76.     CStr255 msg;
  77.     Boolean mightHaveNewGroups = true;
  78.     short sizeofTPrefRec;
  79.     FSSpec **docList = nil;
  80.     short numDocs;
  81.     long systemVersion;
  82.     long quickdrawVersion;
  83.     OSErr err;
  84.     
  85.     gLifeBoat = NewHandle(kLifeBoatSize);
  86.     if (MemError() == noErr)
  87.         gSinking = false;
  88.     MoveHHi(gLifeBoat);
  89.     HLock(gLifeBoat);
  90.     
  91.     InitGraf(&qd.thePort);
  92.     InitFonts();
  93.     InitWindows();
  94.     InitMenus();
  95.     TEInit();
  96.     InitDialogs(nil);
  97.     InitCursor();
  98.     InitCursorCtl(nil);
  99.  
  100.     FlushEvents(everyEvent,0);
  101.     EventAvail(everyEvent,&ev);
  102.  
  103.     err = Gestalt(gestaltSystemVersion, &systemVersion);
  104.     if (err != noErr || systemVersion < 0x0700) {
  105.         ErrorMessage("NewsWatcher requires System 7.0 or later.");
  106.         ExitToShell();
  107.     }
  108.     
  109.     err = Gestalt(gestaltQuickdrawVersion, &quickdrawVersion);
  110.     gHasColorQD = err == noErr && quickdrawVersion >= gestalt8BitQD;
  111.  
  112.     gDesktopExtent = (**GetGrayRgn()).rgnBBox;
  113.     gDragRect = gDesktopExtent;
  114.     InsetRect(&gDragRect,4,4);
  115.     SetRect(&gWindLimits,kMinWindWidth,kMinWindHeight,6000,6000);
  116.     gIBeamCurs = **(GetCursor(iBeamCursor));
  117.     SpinCursor(0);
  118.     
  119.     sizeofTPrefRec = sizeof(TPrefRec);
  120.     if (sizeofTPrefRec != kTPrefRecSize) {
  121.         sprintf(msg, "sizeof(TPrefRec) is %d, should be %d", sizeofTPrefRec,
  122.             kTPrefRecSize);
  123.         ErrorMessage(msg);
  124.         ExitToShell();
  125.     }
  126.  
  127.     SetUpMenus();
  128.  
  129. /*
  130. ErrorMessage("NewsWatcher 2.0d14 test version 4. Special test version! Please do not redistribute!");
  131. */
  132.     
  133.     InitializeAppleEvents();
  134.     GetInitialDocList(&docList, &numDocs);
  135.     LocatePrefsFile(docList, numDocs);
  136.     FSMakeFSSpec(gPrefsFile.vRefNum, gPrefsFile.parID, kFilterName, &gFilterFile);
  137.     gStartupOK = ReadPrefs();
  138.     if (gPrefs.logActionsToFile) OpenLogFile();
  139.  
  140.     #ifdef FILTERS
  141.         if (gStartupOK) gStartupOK = ReadKillFile();
  142.     #endif
  143.  
  144.     if (gStartupOK) gStartupOK = StartNNTP();
  145.     
  146.     if (gStartupOK && gNumGroups == 0) {
  147.         gStartupOK = ReadGroupsFromServer();
  148.         mightHaveNewGroups = false;
  149.     }
  150.     
  151.     if (gStartupOK) gStartupOK = CreateFullGroupListWindow();
  152.     
  153.     if (gStartupOK && mightHaveNewGroups && gPrefs.checkForNewGroups)
  154.         CheckForNewGroups();
  155.  
  156.     if (gStartupOK) {
  157.         if (gPrefs.autoFetchnewsrc) {
  158.             DoGetGroupListFromHost(true);
  159.             gCancel = false;
  160.         }
  161.         OpenDocList(docList, numDocs);
  162.     }
  163.     
  164.     if (gStartupOK) CreateNewGroupListWindow();
  165.     
  166.     if (!gStartupOK) {
  167.         EndNNTP();
  168.         strcpy(msg, "An error occurred during the startup process, ");
  169.         strcat(msg, "or you canceled the startup process. ");
  170.         strcat(msg, "You may adjust NewsWatcher’s preferences, ");
  171.         strcat(msg, "but you will not be able to read or post news.");
  172.         ErrorMessage(msg);
  173.     }
  174.     
  175.     gStartingUp = false;
  176. }
  177.